// pages/volunteer/components/picker/index.js
const {
  voluntaryUpdateSort
} = require('../../../../api/ai')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    visible: {
      type: Boolean,
      value: false
    },
    type: {
      type: String,
      value: ''
    },
    range: {
      type: Array,
      value: false
    },
    rangeKey: {
      type: String,
      value: ''
    },
    //初始index
    value: {
      type: Number,
      value: 0
    },

  },
  observers: {
    'value': function (val) {
      this.setData({
        current: val
      })
    },
    'range': function (val) {
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    current: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    confirm() {
      const {
        range,
        current,
        value,
        type
      } = this.data
      // if (value == current) {
      //   this.hide()
      //   return
      // }
      const _self = this
      //新的
      if (range[current].checked) {
        this.hide()
        _self.setData({
          range
        })
        _self.triggerEvent('desc', {
          current,
          range,
          value,
          type:'change',
        })
        return
      }
      // 
      if (range[value].checked) {
        this.hide()
        _self.setData({
          range
        })
        _self.triggerEvent('desc', {
          current,
          range,
          value,
          type:'origin'
        })
        return
      }
      this.hide()
      this.triggerEvent('change', {
        current,
        range
      })
    },
    hide() {
      this.setData({
        visible: false
      })
    },
    changeIndex(e) {
      this.setData({
        current: e.detail.current
      })
    }
  }
})